<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:fn="http://java.sun.com/jsp/jstl/functions"
	xmlns:p="http://primefaces.org/ui"
	xmlns:cc="http://java.sun.com/jsf/composite"
	xmlns:hmrSearch="http://java.sun.com/jsf/composite/search"
	xmlns:hmrTable="http://java.sun.com/jsf/composite/table"
	xmlns:hmrDetail="http://java.sun.com/jsf/composite/detail"	>

<cc:interface>
	<cc:attribute name="handler"					type="com.hemerasolutions.v2trainer.component.interfaces.detail.ExerciseGroupDetailsCompInterface" required="true"/>
	<cc:attribute name="update"						type="java.lang.String"		default="@none" required="false"/>
	<cc:attribute name="editable"					type="java.lang.Boolean" 	default="true" required="false" />

</cc:interface>

<cc:implementation>
	<span id="#{cc.clientId}" >
		<ui:param name="separator" value=":"/>
		<ui:param name="jseparator" value="\\:"/>	
		
		<p:tabView id="tabExerciseGroup" style="border:none;min-height:99%;width:99%;position:relative" cache="false" rendered="#{cc.attrs.handler.exerciseGroup != null}">
			<p:tab title="#{msgs.BasicData} - #{msgs.Version}: #{cc.attrs.handler.exerciseGroup.version}">
				<h:form id="exerciseGroupForm" prependId="false">
					<h:panelGrid style="height:90%" columns="1" columnClasses="top-align" > 
						<h:column>
							<div style="display:block;height:90%;width:600px">
								<h:panelGrid columns="2" style="white-space:nowrap;"  > 
						            <h:outputLabel value="#{msgs.Name} :" for="exerciseGroupName" />
						            <p:inputText id="exerciseGroupName"     value="#{cc.attrs.handler.exerciseGroup.name}" maxlength ="20" size="20" 
						            	required="false" requiredMessage="#{msgs.ExerciseGroupNameObligatory}">
						            </p:inputText>

									<h:outputLabel value="#{msgs.Description} :" for="exerciseGroupDescription" style="white-space:nowrap;"  />
									<p:inputTextarea id="exerciseGroupDescription" rows="4" cols="50"
										counter="counter" maxlength="180"
										counterTemplate="{0} #{msgs.CharsRemaining}" autoResize="false"
										value="#{ cc.attrs.handler.exerciseGroup.description}" />
									<p:spacer />
									<h:outputText id="counter" />
			
									<h:outputLabel value="#{msgs.Obs} :" for="exerciseGroupObs" />
									<p:inputTextarea id="exerciseGroupObs" rows="4" cols="50"
										counter="counterExerciseGroupObs" maxlength="180"
										counterTemplate="{0} #{msgs.CharsRemaining}" autoResize="false"
										value="#{ cc.attrs.handler.exerciseGroup.obs}" />
									<p:spacer />
									<h:outputText id="counterExerciseGroupObs" />
					
						            <h:outputText value="#{msgs.Status} :" />
						            <p:selectOneRadio value="#{cc.attrs.handler.exerciseGroup.active}" >
						                <f:selectItem itemLabel="#{msgs.Active}"  	itemValue="true"   />
						                <f:selectItem itemLabel="#{msgs.Inactive}"	itemValue="false" />
						            </p:selectOneRadio>
					
									<h:outputLabel 	value="#{msgs.CreatedAt} :"		for="exerciseGroupCreatedAt" rendered="#{cc.attrs.handler.exerciseGroup.id != null}"  />
									<p:inputText  	id="exerciseGroupCreatedAt" 	value="#{cc.attrs.handler.exerciseGroup.createdAt}" disabled="true" rendered="#{cc.attrs.handler.exerciseGroup.id != null}"  >
										<f:convertDateTime locale="pt" dateStyle="long" pattern="dd/MM/yyyy HH:mm" />
									</p:inputText>
					
									<h:outputLabel 	value="#{msgs.ChangedAt} :"		for="exerciseGroupChangedAt" rendered="#{cc.attrs.handler.exerciseGroup.id != null}" />
									<p:inputText  	id="exerciseGroupChangedAt" 	value="#{cc.attrs.handler.exerciseGroup.lastChange}" disabled="true" rendered="#{cc.attrs.handler.exerciseGroup.id != null}" >
										<f:convertDateTime locale="pt" dateStyle="long" pattern="dd/MM/yyyy HH:mm" />
									</p:inputText>
					
									<h:outputLabel 	value="#{msgs.ChangedBy} :"		for="exerciseGroupChangedBy" rendered="#{cc.attrs.handler.exerciseGroup.id != null}" />
									<p:inputText  	id="exerciseGroupChangedBy" 	value="#{cc.attrs.handler.exerciseGroup.changedBy.email}" disabled="true" rendered="#{cc.attrs.handler.exerciseGroup.id != null}" />
									
									<h:outputLabel 	value="#{msgs.Library} :"		for="exerciseGroupLibrary" />
									<p:selectOneMenu id="exerciseGroupLibrary" value="#{cc.attrs.handler.exerciseGroup.versionableExerciseGroup.library}"	  disabled="#{cc.attrs.handler.exerciseGroup.id != null}" converter="#{libraryConverter}">
						            	<f:selectItems value="#{cc.attrs.handler.activeUser.librarys}" var="library" itemLabel="#{library.name}" itemValue="#{library}" />
									</p:selectOneMenu>
			
								</h:panelGrid>
							</div>
						</h:column>
					</h:panelGrid>	
					<div align="left" style="position:absolute;bottom:0;left:0;" >
						<p:outputPanel layout="block" rendered="#{cc.attrs.handler.exerciseGroup != null}">
							<p:commandButton id="saveButton"  	value="#{msgs.Save}"		actionListener="#{cc.attrs.handler.saveExerciseGroup}"  	process=":#{cc.clientId}"	 		
								ajax="true"	update="#{cc.attrs.update}"		icon="ui-icon-disk"		rendered="#{cc.attrs.handler.exerciseGroup.id != null}" />
							<p:commandButton id="createButton" 	value="#{msgs.Create}"	actionListener="#{cc.attrs.handler.createExerciseGroup}"		process=":#{cc.clientId}" 
								ajax="true"	update="#{cc.attrs.update}"		icon="ui-icon-document"	rendered="#{cc.attrs.handler.exerciseGroup.id == null}" />
							<p:spacer width="50px"/>	
							<p:commandButton  value="#{msgs.Cancel}" update="#{cc.attrs.update}"	action="#{cc.attrs.handler.cancelChange}"	icon="ui-icon-cancel"/>
							<p:blockUI block=":#{cc.clientId}:tabExerciseGroup" trigger="createButton saveButton" />
						</p:outputPanel>
					</div>	 
				</h:form>	
					
			</p:tab>
			<p:tab title="#{msgs.Exercises} - #{msgs.Version}: #{cc.attrs.handler.exerciseGroup.version}">	
				<h:form prependId="false">
					<p:outputPanel layout="block">
						<p:commandButton value=" #{cc.attrs.handler.exerciseGroup.modality != null ? msgs.Modify : msgs.Select } #{msgs.Modality}" actionListener="#{cc.attrs.handler.toSearchModality}" 
							update=":#{cc.clientId}:modalitySearchDialog" oncomplete="PF('wfindModalityDialog_#{cc.id}').show();"/>
						
						<h:outputText value="#{msgs[cc.attrs.handler.exerciseGroup.modality.trainingType.name]}" style="margin-left:20px;white-space: nowrap;" rendered="#{cc.attrs.handler.exerciseGroup.modality != null}"/>
						<h:outputText value="#{cc.attrs.handler.exerciseGroup.modality.name} - #{msgs.Version}: #{cc.attrs.handler.exerciseGroup.modality.version} " 
							rendered="#{cc.attrs.handler.exerciseGroup.modality != null}"	style="white-space: nowrap;"/>
					
					</p:outputPanel>
				</h:form>
					
				<hmrTable:groupedExerciseTable id="exerciseGroupTable" handler="#{cc.attrs.handler.exerciseGroupTable}" editable="#{cc.attrs.editable}" />
			
				<h:form id="formGroupExercises" prependId="false">
					<p:outputPanel layout="block" rendered="#{cc.attrs.handler.exerciseGroup != null}" style="position:absolute;bottom:0px;left:0px">
						<p:commandButton value="#{msgs.Save}"	icon="ui-icon-disk" 	process=":#{cc.clientId}:tabExerciseGroup:exerciseGroupTable"		rendered="#{cc.attrs.handler.exerciseGroup.id != null}"
							oncomplete="$(' ##{fn:replace(cc.clientId, separator, jseparator)}\\:tabExerciseGroup\\:saveButton').click()" />
						<p:commandButton value="#{msgs.Create}"	icon="ui-icon-document"	process=":#{cc.clientId}:tabExerciseGroup:exerciseGroupTable"		rendered="#{cc.attrs.handler.exerciseGroup.id == null}" 
							oncomplete="$(' ##{fn:replace(cc.clientId, separator, jseparator)}\\:tabExerciseGroup\\:createButton').click()" />
						<p:spacer width="50px" height="1px"/>	
						<p:commandButton  value="#{msgs.Cancel}" update="#{cc.attrs.update}"	action="#{cc.attrs.handler.cancelChange}"	icon="ui-icon-cancel"/>
					</p:outputPanel>		
		
				</h:form>
			</p:tab>
		</p:tabView>
	</span>

	<p:dialog id="modalitySearchDialog" header="#{msgs.FindModality}" modal="true" appendTo="@(body)"  widgetVar="wfindModalityDialog_#{cc.id}">
		<hmrSearch:modalitySearch handler="#{cc.attrs.handler.modalitySearch}" showResultsPanel="true" 
			updateOnSelect=":#{cc.clientId}:tabExerciseGroup:exerciseGroupForm" onCompleteSelect="wfindModalityDialog_#{cc.id}.hide();"   />
	</p:dialog>		
			

		

</cc:implementation>
</html>	